import { BasePageDto, BaseScrollPageDto } from '@/common/base/base.dto';
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
import {
  IsArray,
  IsEnum, IsInt,
  IsNotEmpty,
  IsOptional,
  IsString,
  Max, MaxLength, Min,
} from 'class-validator';
import {
  ArticleNormalCategory,
} from 'common/utils/data';
import {
  SearchArticleStatusByAdmin,
  UpdateArticleStatusByAdmin,
  UpdateArticleStatusByUser,
} from './article.enum';

export class ArticleIndexNormalDto extends BaseScrollPageDto {
  @IsOptional()
  @ApiPropertyOptional()
  @IsEnum(ArticleNormalCategory)
  category?: ArticleNormalCategory;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  keyword?: string;
}

export class ArticleMineDto extends BaseScrollPageDto {
  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  status?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  title?: string;
}

export class ArticleCreateDto{
  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @MaxLength(50)
  title: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  @MaxLength(1000)
  desc?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsArray()
  keywords?: string[];

  @IsOptional()
  @ApiPropertyOptional()
  @IsArray()
  thumbnails?: string[];

  @IsOptional()
  @ApiPropertyOptional()
  @IsArray()
  categories?: ArticleNormalCategory[];

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  @MaxLength(999999)
  content?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  @MaxLength(999999)
  contentRaw?: string;
}

export class ArticleUpdateDto extends PartialType(ArticleCreateDto) {
  @IsOptional()
  @ApiPropertyOptional()
  @IsEnum(UpdateArticleStatusByUser)
  status?: UpdateArticleStatusByUser;
}

export class ArticleAdminIndexDto extends BasePageDto {
  @IsOptional()
  @ApiPropertyOptional()
  @IsEnum(ArticleNormalCategory)
  category?: ArticleNormalCategory;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  title?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsEnum(SearchArticleStatusByAdmin)
  status?: SearchArticleStatusByAdmin;
}

export class ArticleAdminUpdateDto {
  @IsOptional()
  @ApiPropertyOptional()
  @IsEnum(UpdateArticleStatusByAdmin)
  status?: UpdateArticleStatusByAdmin;

  @IsOptional()
  @ApiPropertyOptional()
  @IsInt()
  @Max(1)
  @Min(0)
  isStick?: number;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  rejectReason?: string;
}

